//
//  NavStyleSKU.m
//  ZITHER
//
//  Created by weixin on 2018/9/2.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "NavStyleSKU.h"

@implementation NavStyleSKU

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUI];
        [self setMasonry];
        
        if ([Main_Token_Model_MANAGER.isToken isEqualToString:@"1"]){
            self.backgroundColor =  Main_Token_Model_MANAGER.backgroundColor ;
        }
    }
    return self;
}


-(void)setUI{
    
    
    
    BaseBtn *btn = [[BaseBtn alloc]initializeFrame:CGRectMake(0,kTopBarSafeHeight+10,50,50) NormalImage:@"common_back" SeleImage:@"common_back"];
    @weakify(self);
    [[btn rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        [self.getNav popViewControllerAnimated:YES];
    }];
    [self addSubview:btn];
    [btn setLocalImage:@"common_back"];
    
    [self addSubview:self.navBtnLike];
    [self addSubview:self.navBtnMore];
    [self addSubview:self.navTitle];
    [self addSubview:self.navTitleSub];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(kStatusBarHeight +14);
        make.left.equalTo(self).offset(14);
        make.width.height.mas_equalTo(20);
        
    }];
 
    
//    CGFloat height = kStatusBarHeight +14+25+14 +25+5+10+28;

//    [self.NavView addSubview:self.btnMore];
}

-(void)setMasonry{
    
    [self.navBtnLike mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).offset(kStatusBarHeight +14);
        make.right.mas_equalTo(self).offset(-14);
        make.width.height.mas_equalTo(25);

    }];
    
    [self.navBtnMore mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).offset(kStatusBarHeight +14);
        make.right.mas_equalTo(self.navBtnLike.mas_left).offset(-14);
        make.width.height.mas_equalTo(25);
    }];
    
    [self.navTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.navBtnLike.mas_bottom).offset(14);
        make.left.mas_equalTo(self).offset(14);
//        make.height.mas_equalTo(25);

    }];
    
    [self.navTitleSub mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.navTitle.mas_bottom).offset(5);
        make.left.mas_equalTo(self).offset(14);
//        make.height.mas_equalTo(15);

    }];
    
}



-(QMUIButton *)navBtnLike{
    if (!_navBtnLike) {
        _navBtnLike = [[QMUIButton alloc]initWithFrame:CGRectMake(kScreenW-60,kTopBarSafeHeight+10,50,50)];
        [_navBtnLike setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_navBtnLike setImage:[UIImage imageNamed:@"nav_btn_collect"] forState:UIControlStateNormal];
        [_navBtnLike setImage:[UIImage imageNamed:@"nav_btn_collected"] forState:UIControlStateSelected];
        @weakify(self);
        [[_navBtnLike rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self);
            self.navBtnLike.selected = !self.navBtnLike.selected;
            
            if (self.blockClick) {
                self.blockClick(0);
            }
            
        }];
        _navBtnLike.backgroundColor = [UIColor clearColor];

    }
    return _navBtnLike;
}

-(QMUIButton *)navBtnMore{
    if (!_navBtnMore) {
        _navBtnMore = [[QMUIButton alloc]initWithFrame:CGRectMake(0,0,1,1)];
        if ([Main_Token_Model_MANAGER.isToken isEqualToString:@"1"]){
            [_navBtnMore setTitleColor:Main_Token_Model_MANAGER.navTitleColor forState:UIControlStateNormal];
        }else{
            [_navBtnMore setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        }
        [_navBtnMore setImage:[UIImage imageNamed:@"nav_btn_more"] forState:UIControlStateNormal];
        @weakify(self);
        _navBtnMore.backgroundColor = [UIColor clearColor];

        [[_navBtnMore rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self);
            QMUIAlertAction *action1 = [QMUIAlertAction actionWithTitle:@"取消" style:QMUIAlertActionStyleCancel handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
                
            }];
            
            
            QMUIAlertAction *action4 = [QMUIAlertAction actionWithTitle:@"终止询价" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
                
                if (self.blockClick) {
                    self.blockClick(1);
                }
                
      
            }];
            
            QMUIAlertAction *ac2 = [QMUIAlertAction actionWithTitle:@"查看接收历史报价" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
                if (self.blockClick) {
                    self.blockClick(2);
                }
              
            }];
            
            
            QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:QMUIAlertControllerStyleActionSheet];
            
            [alertController addAction:action1];
            
            [alertController addAction:ac2];
            
            [alertController addAction:action4];
            
            [alertController showWithAnimated:YES];
        }];
        
    }
    return _navBtnMore;
}

//-(QMUIButton *)navBtnMore{

//        if (![self.model.myEnquiryFlag isEqualToString:@"1"]) {
//            _navBtnMore.selected = YES;
//        }
        
//        [[_navBtnMore rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
//
//    }
//    return _navBtnMore;
//}

-(QMUILabel *)navTitle{
    if (!_navTitle) {
        _navTitle = [[QMUILabel alloc]initWithFrame:CGRectMake(15,kTopBarSafeHeight+70 , kScreenW, 25)];
        _navTitle.font = [UIFont fontWithName:@"Helvetica-Bold" size:34];
        _navTitle.backgroundColor = [UIColor clearColor];
        if ([Main_Token_Model_MANAGER.isToken isEqualToString:@"1"]){
            _navTitleSub.textColor = Main_Token_Model_MANAGER.navTitleColor;
        }
//        _navTitle.text = @"300003000-30000";
    }
    return _navTitle;
}

-(QMUILabel *)navTitleSub{
    if (!_navTitleSub) {
        _navTitleSub = [[QMUILabel alloc]initWithFrame:CGRectMake(15,kTopBarSafeHeight+100 , kScreenW, 15)];
        _navTitleSub.font = [UIFont systemFontOfSize:13];
        _navTitleSub.backgroundColor = [UIColor clearColor];
        if ([Main_Token_Model_MANAGER.isToken isEqualToString:@"1"]){
            _navTitleSub.textColor = Main_Token_Model_MANAGER.navTitleColor ;
        }

//        _navTitleSub.text = @"绿鬼水鬼/绿鬼水鬼";
    }
    return _navTitleSub;
}

@end
